﻿HmJS.$Import('core.element');
HmJS.$Import('core.more');

/*
---
version: 0.9-3
description: Rounded
license: MIT-style license
download: http://mootools.net/forge/p/rounded
source: http://github.com/fritzZz/Rounded

authors:
- Alessandro Franzi aka fritzzz (http://franziale.blogspot.com)
 
requires:
core/1.2.4: '*'
 
provides:
- Rounded
...
*/
HmJS.register('util.effect.Rounded', function ($ns) {

	var $defined = function (obj) {
		return (obj != null);
	};

	return new Class({

		Implements: [Events, Options],

		options: {
			radius: "10px",
			selector: ".gc",
			cornered: "good-cornered"
		},

		styles: {
			gecko: {
				topleft: "-moz-border-radius-topleft",
				topright: "-moz-border-radius-topright",
				bottomleft: "-moz-border-radius-bottomleft",
				bottomright: "-moz-border-radius-bottomright",
				radius: "-moz-border-radius"
			},
			webkit: {
				topleft: "-webkit-border-top-left-radius",
				topright: "-webkit-border-top-right-radius",
				bottomleft: "-webkit-border-bottom-left-radius",
				bottomright: "-webkit-border-bottom-right-radius",
				radius: "-webkit-border-radius"
			}
		},

		initialize: function (element, options) {
			this.setOptions(options);
			var params = Array.link(arguments, { 'container': Type.isElement, 'options': Type.isObject, 'togglers': $defined, 'elements': $defined });

			// retrieve browser engine
			this.layout = null;
			if (Browser.safari || Browser.chrome) {
				this.layout = "webkit";
			}
			if (Browser.firefox) {
				this.layout = "gecko";
			}
			if (this.layout == null) {
				return false;
			}

			// Round corner
			this.how = new Hash(this.how || {
				radius: this.options.radius
			});
			this.how.each(function (value, key, obj) {
				// ignore other styles completly
				if ($defined(this.styles[this.layout][key]) == false) {
					return;
				}
				this.how.set(this.styles[this.layout][key], value);
				this.how.erase(key);
			} .bind(this));

			// Attach css class
			if (element != null) {
				element.setStyles(this.how.getClean()).addClass(this.options.cornered);
			} else {
				$$(this.options.selector).setStyles(this.how.getClean()).addClass(this.options.cornered);
			}
			return true;
		}

	});

});